package com.banciyuan.bcywebview.utils.db;

import android.content.Context;

import com.banciyuan.bcywebview.base.helper.data.DataCenter;

import java.util.ArrayList;

import de.greenrobot.daoexample.dao.DaoSession;
import de.greenrobot.daoexample.model.User;
import de.greenrobot.daoexample.dao.UserDao;

/**
 * 用于获得greendao的工具类。
 * @author hfxt2008
 */
public class DBHelper {

	private static Context mContext;
	private static DBHelper instance;
	private UserDao mUserDao;

	public static DBHelper getInstance(Context context) {
		if (instance == null) {
			instance = new DBHelper();
			if (mContext == null) {
				mContext = context;
			}
			// 数据库对象
			DaoSession daoSession = DataCenter.getInstance().getDataBaseHelper().getDaoSession(mContext);
			instance.mUserDao = daoSession.getUserDao();

		}
		return instance;
	}

	// User操作
	/** 添加数据 */
	public void addUser(User user) {
		mUserDao.insert(user);
	}

	/** 查询 */
	public ArrayList<User> getUser() {
		return (ArrayList<User>) mUserDao.loadAll();
	}

	/** 删除 */
	public void deleteUser() {
		mUserDao.deleteAll();
	}
}